package com.example.demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductService {
    private final ProductRepository productRepository;

    @Autowired
    public ProductService(ProductRepository productRepository) {
        this.productRepository = productRepository;
    }

    public List<Product> getAllProducts() {
        // 在这里编写产品检索逻辑，例如从数据库中检索产品列表
        return productRepository.findAll();
    }

    public Product createProduct(Product product) {
        // 在这里编写产品创建逻辑，例如将新产品保存到数据库
        return productRepository.save(product);
    }
}
